{------------------------------------------------------------------------------
#
#	Apple Macintosh Developer Technical Support
#
#	MacApp Color QuickDraw Fractal Sample Application
#
#	FracApp
#
#	MFracApp.p	-	Pascal Source
#
#	Copyright © 1988 Apple Computer, Inc.
#	All rights reserved.
#
#	Versions:	1.0					8/88
#
#	Components:	MFracApp.p			August 1, 1988
#				UFracApp.p			August 1, 1988
#				UFracApp.inc1.p		August 1, 1988
#				FracApp.r			August 1, 1988
#				FracApp.make		August 1, 1988
#
#	This is a program to calculate the Mandelbrot set, allowing you to zoom in on areas
#	that are selected with the mouse.  There are some special color tricks played
#	in order to make the program more jazzy.  A special color table is used to give
#	smooth transitions from one color to the next.  Color table animation is also
#	supported, for the wowem effect of flowing Mandelbrot images. 
#	The program is written in MacApp 1.1, which explains why it has a real user
#	interface.  Mandelbrot images take about 30 minutes to calculate.  It is
#	Juggler aware so you can put the program in the background where it will
#	continue to calculate, while you do something more important, like look at 
#	the source code.  It also handles multiple documents, and reading/writing of
#	PICT files using the bottlenecks to minimize the memory hit.
#	
#	This program is intended to be a real world example of handling color in a
#	nontrivial fashion.  As such it has some rather special color requirements,
#	and those donÕt match the current system architecture very well.  The program
#	is designed to be compatible with the future, it will not break in future
#	systems.  However, it does not use the Palette Manager, which means that
#	there will be situations where the colors will not look right in either FracApp
#	or another program running under MultiFinder.  The approach that FracApp
#	uses is thus not the preferred Apple approach and does NOT have the Apple
#	seal of approval from engineering.  The only way to get the stamp of approval
#	is to use the Palette Manager.  To do a program of this form, you cannot
#	use the Palette Manager without some extra hacks that are compatibility
#	risks in themselves.  So... use at your own risk.  If you are forced to revise your 
#	program because you followed this as an example, you cannot gripe to Apple, since
#	it is not fully approved.  You just have to change your program, which I hope is no
#	big deal.  You can give this code to other people, as long as they recognize
#	that it is not fully approved too. 
#	
#	Unless you have very special color requirements, you should use the Palette 
#	Manager.  It works for most things, and is much easier to use than the
#	approach taken here.  There are a few things it wonÕt do of course, leading
#	to this code.  If you can do it, use the Palette Manager and save yourself
#	some grief.
#			Written in MacApp Object Pascal code.
#			Compatibility rating = 2.  (nothing will break, but it may not
#				always look correct.)
#
------------------------------------------------------------------------------}
{copyright 1988 by Bob.  All rights reserved.
	February 1, 1988. 
	Written by Bo3b Johnson of Developer Technical Support. }

PROGRAM FracApp;

USES
	{$LOAD MacIntf.LOAD}
		MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
	{$LOAD UMacApp.LOAD}
		UObject, UList, UMacApp,
	{$LOAD UBobLips.LOAD}
		PaletteMgr, UPrinting,
	{$LOAD}

	UFracApp;


VAR
	{The application object:}
	gFracAppApplication:   TFracAppApplication;
	error:	Integer;
	

FUNCTION ForceEnvirons(minimumSystemVersion: INTEGER;
							  minimumProcessor: INTEGER; needsFPU: BOOLEAN;
							  needsColorQD: BOOLEAN;
							  minimumATDrvrVersNum: INTEGER): BOOLEAN;

	VAR
		error: OSErr;
		theWorld: SysEnvRec;

	BEGIN
		error := SysEnvirons(1,theWorld);
		WITH theWorld DO
			ForceEnvirons := (systemVersion >= minimumSystemVersion) AND
								  (processor >= minimumProcessor) AND (hasFPU >=
								  needsFPU) AND (needsColorQD >= hasColorQD) AND
								  (atDrvrVersNum >= minimumATDrvrVersNum);
	END;


BEGIN
	{Initialize the Toolbox, making 8 calls to MoreMasters:}
	InitToolbox(8);

		{ The first thing we have to do is ensure that we can run in this environment.  
			We must do a ForceEnvirons to avoid crashing needlessly on machines where
			we have no color or 881.  The minimum system is 4.2 since we need the more
			robust Palette Manager.  We donÕt use 020 code, but we require an FPU.  We
			also require colorQD.  If we donÕt have the stuff we need, we will alert and
			leave.  }
 	IF NOT ForceEnvirons($0420, envDontCare, TRUE, TRUE, envDontCare) THEN
		Failure (kWrongMachine, 0);
	
	{Initialize the UPrinting unit:}
	InitPrinting;

	{Allocate a new TFracAppApplication object:}
	New(gFracAppApplication);

	{Initialize that new object:}
	gFracAppApplication.IFracAppApplication(kFileType);

	{Run the application.  When it's done, exit.}
	gFracAppApplication.Run;
END.
